<?php
/**
 * Created by PhpStorm.
 * User: haobin
 * Date: 2016/10/24
 * Time: 15:49
 */
//动态页面
require('../conn.php');
require('../functions.php');
$sql = "select * from `link` where type = 2";
$row_user = $mysql->query($sql);
$uid = $_GET['uid'];
$aid = $_GET['aid'];
//设置默认title username正在观看微有趣#栏目#
$user = $mysql->query("select `name` from `user` WHERE `id`={$uid}");
$ainfo = $mysql->query("select `code_content` as `content` from `news` WHERE id={$aid}");
$title = $user[0]['name'] . "正在观看微有趣#" . $ainfo[0]['content'] . "#";
//获取动态信息
$comment = $mysql->query("select * from `news` WHERE id={$aid}");
$commentInfo = $comment[0];
$commentInfo['content'] = str_replace("￥","",$commentInfo['content']);
switch ($commentInfo['flag']) {
    case 1://普通动态
        $content = "<p>{$commentInfo['content']}</p>";
        //截取部分内容作为标题
        $title = mb_substr($commentInfo['content'], 0, 14);
        if($commentInfo['img']){
            $imgPics = $commentInfo['img'];
            $imgArr = explode(",", $imgPics);
            $image = WEB . "/".$imgArr[0];
        }
        break;
    case 2://图片，只取第一张
        $imgPics = $commentInfo['img'];
        $imgArr = explode(",", $imgPics);
        $img = WEB . $imgArr[0];
        $content = "<img src='{$img}'>";
        break;
    case 3://gif
        $content = "<img src='{$commentInfo['img']}'>";
        if ($commentInfo['content']) {
            $title = $commentInfo['content'];
        }
        break;
    default://视频
        if ($commentInfo['content']) {
            $title = $commentInfo['content'];
        }
        $content = "<video class=\"video-player\" src=\"{$commentInfo['video_url']}\" poster=\"{$commentInfo['img']}\" type=\"video/mp4\" controls=\"true\" style=\"width: 100%;\"></video>";
        break;
}
$content = str_replace(",", "", $content);
//获取用户信息
$userRow = $mysql->query("select * from `user` WHERE `id`={$uid}");
$user = $userRow[0];
//获取评论信息
$comments = $mysql->query("select * from `comment` where `nid`={$aid} ORDER BY `pnum` DESC limit 2");
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo $title; ?></title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="css/share.css"/>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript">
    </script>
    <script src="js/share.js"></script>
    <script>
        function changeSize() {
            var propo = $(window).width() / 640;
            $('html').css('font-size', 40 * propo + 'px');
        }
        ;
        changeSize();
        $(window).resize(function () {
            changeSize();
        });
    </script>
</head>
<body>
<div class="wrap">
    <div class="header">
        <div class="logo">
            <img src="images/logo.png" alt="logo"/>
        </div>
        <div class="ms">
            <h2>微有趣</h2>

            <p>美女，内涵，搞笑</p>
        </div>
        <div class="down downapp1">
            立即打开
        </div>
    </div>
    <div class="con">
        <div class="content">
            <?= $content ?>
            <?php if($image):?>
            <img src="<?=$image?>">
            <?php endif;?>
        </div>
        <div class="user">
            <div class="userinfo clearfix">
                <div class="wxhead">
                    <img src="<?= $user['head'] ?>" alt="wx头像"/>
                </div>
                <h3><?= $user['name'] ?></h3>

                <div class="more downapp">
                    查看更多
                </div>
            </div>
        </div>
        <div class="title">
            <?= $title ?>
        </div>
        <div class="zan">
            <ul class="clearfix">
                <li>
                    <div class="icon">
                        <img src="images/zan.png"/>
                    </div>
                    <p class="zannum"><?= $commentInfo['pnum'] ?></p>
                </li>
                <li>
                    <div class="icon">
                        <img src="images/comt.png"/>
                    </div>
                    <p class="zannum"><?= $commentInfo['cnum'] ?></p>
                </li>
                <li>
                    <div class="icon">
                        <img src="images/send.png"/>
                    </div>
                    <p class="zannum"><?= $commentInfo['snum'] ?></p>
                </li>
            </ul>
        </div>

        <div class="fg">

        </div>
        <div class="comment">
            <div class="type">
                <img src="images/hot.png"/>

                <p>热门评论</p>
            </div>
            <div class="list">
                <ul>
                    <?php foreach ($comments as $comment):
                        $uPic = $mysql->query("select `head`,`name` from `user` WHERE `id`={$comment['uid']}");
                        $name = $uPic[0]['name'];
                        $head = $uPic[0]['head'];
                        ?>
                        <li>
                            <div class="com_info">
                                <div class="com_head">
                                    <img src="<?= $head ?>"/>
                                </div>
                                <div class="com_name">
                                    <?= $name ?>
                                </div>
                                <div class="com_zan">
                                    <img src="images/zan.png"/>
                                    <?= $comment['pnum'] ?>
                                </div>
                            </div>
                            <div class="com_con">
                                <p><?= $comment['content'] ?></p>
                            </div>
                        </li>
                    <?php endforeach; ?>
                </ul>
                <div class="com_more downapp">
                    更多评论
                </div>
            </div>


            <div class="tj">
                <div class="tj_title">
                    <img src="images/video.png"/>
                    精彩视频
                </div>
                <ul class="clearfix tj_list">
                    <?php
                    $sqlimg = "select * from `news` where `img` like 'http://%' And video_url !='' order by rand() limit 6 ";
                    $resultimgs = $mysql->query($sqlimg);
                    foreach ($resultimgs as $key => $val) {
                        ?>
                        <li class="downapp2">
                            <img src="<?= $val['img'] ?>"/>
                            <p><span>下载app</span><?= $val['content'] ?></p>
                        </li>
                    <?php } ?>
                </ul>
                <div class="tj_more">
                    都翻到这儿了，就下载个微有趣吧~
                </div>
            </div>
        </div>
    </div>
    <div class="footer">
        <div class="logo">
            <img src="images/logo.png" alt="logo"/>
        </div>
        <div class="ms">
            <h2>微有趣</h2>

            <p>美女，内涵，搞笑</p>
        </div>
        <div class="down downapp3">
            立即打开
        </div>
    </div>
</div>
<div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260183915&web_id=1260183915" language="JavaScript"></script>
</div>
<script type="text/javascript">
    var platform = navigator.platform;
    $(".downapp").click(function () {
        window.location.href = "./adrecord.php?uid=<?=$uid?>&aid=<?=$aid?>&type=0&platform="+platform;
    })
    $(".downapp1").click(function () {
        window.location.href = "./adrecord.php?uid=<?=$uid?>&aid=<?=$aid?>&type=1&platform="+platform;
    })
    $(".downapp2").click(function () {
        window.location.href = "./adrecord.php?uid=<?=$uid?>&aid=<?=$aid?>&type=2&platform="+platform;
    })
    $(".downapp3").click(function () {
        window.location.href = "./adrecord.php?uid=<?=$uid?>&aid=<?=$aid?>&type=3&platform="+platform;
    })
</script>

</body>
</html>
